﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using ModelCheckUtility.ControlLayer;

namespace ModelCheckUtility.ModelLayer
{
	public class BaseRoomPacker : BaseElementPacker
	{
		public Room ThisRoom
		{
			get
			{
				return this.m_thisRoom;
			}
		}

		public Document UseDocument
		{
			get
			{
				return this.m_useDocument;
			}
		}

		public double NowDownZ
		{
			get
			{
				return this.m_dNowDownZ;
			}
		}

		public double NowTopZ
		{
			get
			{
				return this.m_dNowTopZ;
			}
		}

		public bool IfAdded
		{
			get
			{
				return this.m_bifAdded;
			}
		}

		public PlanCircuit ThisPlanCircuit
		{
			get
			{
				return this.m_thisPlanCircuit;
			}
		}

		public List<BaseDoorPacker> LstBaseDoorPacker
		{
			get
			{
				if (this.m_lstDoors == null)
				{
					this.m_lstDoors = new List<BaseDoorPacker>();
				}
				return this.m_lstDoors;
			}
		}

		public List<List<BaseBoundarySegmentPacker>> LstLstBoundarySegmentPacker
		{
			get
			{
				if (this.m_lstlstBoundarySegmentPacker == null)
				{
					this.m_lstlstBoundarySegmentPacker = new List<List<BaseBoundarySegmentPacker>>();
				}
				return this.m_lstlstBoundarySegmentPacker;
			}
			internal set
			{
				this.m_lstlstBoundarySegmentPacker = value;
			}
		}

		public List<BaseRoomPacker> LstNearBaseRoomPacker
		{
			get
			{
				if (this.m_lstNearBaseRoomPacker == null)
				{
					this.m_lstNearBaseRoomPacker = new List<BaseRoomPacker>();
				}
				return this.m_lstNearBaseRoomPacker;
			}
		}

		public int RoomId
		{
			get
			{
				return this.m_nRoomId;
			}
		}

		public PlanarFace NowDownFace
		{
			get
			{
				return this.m_nowDownFace;
			}
		}

		public List<KeyValuePair<BaseHostInRoomPacker, XYZ>> LstHostElementPacker
		{
			get
			{
				if (this.m_lstHostElementPacker == null)
				{
					this.m_lstHostElementPacker = new List<KeyValuePair<BaseHostInRoomPacker, XYZ>>();
				}
				return this.m_lstHostElementPacker;
			}
		}

		public XYZ ThisLocation
		{
			get
			{
				return this.m_thisLocation;
			}
		}

		public BaseRoomPacker(Room inputValue, RevitLinkInstance useLinkInstance = null) : base(inputValue, useLinkInstance, null)
		{
			this.m_thisRoom = inputValue;
			if (this.m_thisRoom != null)
			{
				this.m_thisLocation = (this.m_thisRoom.Location as LocationPoint).Point;
				this.m_useDocument = this.m_thisRoom.Document;
				this.m_nRoomId = this.m_thisRoom.Id.IntegerValue;
				this.m_dNowDownZ = this.m_thisRoom.Level.Elevation;
				this.m_dNowTopZ = Utility.GetAllLevelZVaue(this.m_useDocument).Find((double k) => k > this.m_dNowDownZ);
				if (this.m_dNowTopZ <= this.m_dNowDownZ)
				{
					this.m_dNowTopZ = double.MaxValue;
				}
				List<PlanarFace> list = Utility.FindZPlanarFace(this.m_thisRoom.get_Geometry(new Options
				{
                    DetailLevel = (ViewDetailLevel)1
				}), null);
				if (0 < list.Count)
				{
					this.m_nowDownFace = list[0];
				}
				else
				{
					this.m_nowDownFace = null;
				}
				if (ElementPackerManger.LstAddRoomIds.Contains(this.RoomId))
				{
					this.m_bifAdded = true;
					return;
				}
				this.m_bifAdded = false;
			}
		}

		public void AddDoor(BaseDoorPacker addedDoor)
		{
			if (addedDoor == null)
			{
				return;
			}
			if (this.m_lstDoors == null)
			{
				this.m_lstDoors = new List<BaseDoorPacker>();
			}
			bool flag = true;
			foreach (BaseDoorPacker baseDoorPacker in this.m_lstDoors)
			{
				if (baseDoorPacker.ThisElementPackerId == addedDoor.ThisElementPackerId)
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				this.m_lstDoors.Add(addedDoor);
			}
		}

		public void AddNearRoom(BaseRoomPacker addedRoomPacker)
		{
			if (addedRoomPacker == null)
			{
				return;
			}
			if (this.m_lstNearBaseRoomPacker == null)
			{
				this.m_lstNearBaseRoomPacker = new List<BaseRoomPacker>();
			}
			bool flag = true;
			foreach (BaseRoomPacker baseRoomPacker in this.m_lstNearBaseRoomPacker)
			{
				if (baseRoomPacker.ThisElementPackerId == addedRoomPacker.ThisElementPackerId)
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				this.m_lstNearBaseRoomPacker.Add(addedRoomPacker);
			}
		}

		public void AddHostedElement(BaseHostInRoomPacker addHostedElementPacker, XYZ addPoint = null)
		{
			if (addHostedElementPacker == null)
			{
				return;
			}
			if (this.m_lstHostElementPacker == null)
			{
				this.m_lstHostElementPacker = new List<KeyValuePair<BaseHostInRoomPacker, XYZ>>();
			}
			bool flag = true;
			foreach (KeyValuePair<BaseHostInRoomPacker, XYZ> keyValuePair in this.m_lstHostElementPacker)
			{
				if (keyValuePair.Key.ThisElementPackerId == addHostedElementPacker.ThisElementPackerId)
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				this.m_lstHostElementPacker.Add(new KeyValuePair<BaseHostInRoomPacker, XYZ>(addHostedElementPacker, addPoint));
			}
		}

		private Document m_useDocument;

		private Room m_thisRoom;

		private XYZ m_thisLocation;

		private bool m_bifAdded;

		private PlanCircuit m_thisPlanCircuit;

		private List<BaseDoorPacker> m_lstDoors;

		private List<List<BaseBoundarySegmentPacker>> m_lstlstBoundarySegmentPacker;

		private List<BaseRoomPacker> m_lstNearBaseRoomPacker;

		private List<KeyValuePair<BaseHostInRoomPacker, XYZ>> m_lstHostElementPacker;

		private PlanarFace m_nowDownFace;

		private int m_nRoomId;

		private double m_dNowDownZ;

		private double m_dNowTopZ;
	}
}
